package com.smartum.mpr.validators;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.smartum.mpr.exception.NotValidaParamException;

public class EmailValidator implements Validator {

	private Pattern pattern;
	private Matcher matcher;

	private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
	        + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";

	public EmailValidator() {
		pattern = Pattern.compile(EMAIL_PATTERN);
	}

	@Override
	public void validate(String text) throws NotValidaParamException {
		matcher = pattern.matcher(text);
		if (!matcher.matches()) {
			throw new NotValidaParamException("not valid email:" + text);
		}
	}

}
